Self modifying code (SMC) is an optimization technique where some software code modifies a part of itself before executing. SMC may be used in just-in-time compilation (JIT) compilation systems such as with the JAVA™ programming language. In systems that use code conversion, self modification of guest code presents a specific problem, as guest code modification (GCM) must be detected and corresponding converted traces in the code cache must be either invalidated or regenerated based on the new code.
Detection of GCM can be challenging because of corner cases that can occur. The corner cases can include code and writable data that are finely interleaved and for Harvard processors, for example having separate instruction and data paths, the GCM may require specific code sequences in guest architecture to make the code change visible if the code was stored in cacheable memory.
The corner cases can further include when code locations are written by memory masters different from a central processing unit (CPU). For example, some direct memory access (DMA) process downloads code from an external peripheral before executing the code. Oftentimes, an Input/Output Memory Management Unit (IOMMU) is present so that the DMA memory write operations are visible to the CPU and can be taken into account.